home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt85jun.lbr
/
LOWLIB.AQM
/
LOWLIB.ASM
Wrap
Assembly Source File
|
1985-09-15
|
8KB
|
318 lines
.nopatchlist
.title " LOWLIB -- ASSEMBLY ROUTINES"
;
; macros
;
.macro pop ; pops tos, tos+1 into %1, %1+1
pla
sta %1
pla
sta %1+1
.endm
;
.macro popb ; pops tos into %1 -- discards tos+1
pla
sta %1
pla
.endm
;
.macro push ; pushes %1,%1+1 onto stack
lda %1+1
pha
lda %1
pha
.endm
;
.macro pushb ; pushes 0,%1 onto stack
lda #00
pha
lda %1
pha
.endm
;
.macro clrstk ; clear stack for function call
pla
pla
pla
pla
.endm
;
.nomacrolist
;
;
.func shr,2
;
;-----------
;
; function Shr(Int,Cnt : Integer) : Integer
;
; does integer shift right Cnt times
;
;-----------
;
return .equ 00
count .equ 02
int .equ 08
;
; save parameters and clear stack for function return
;
pop return ; save return address
clrstk ; clear saved space on stack
popb count ; get count value for loop (byte)
ldy count ; check value of count
beq quick_exit ; if count = 0, then leave
pop int ; save integer
;
; set up for loop -- shift right until done
;
rol a ; preserve sign of integer
loop php ; save flags (with sign)
ror int+1 ; do shift
ror int ; for both bytes
plp ; restore flags
dey ; decrement count
bne loop ; continue until done
;
; return integer and exit
;
push int ; if shifted, push int back on stack
quick_exit
push return ; restore return address
rts ; and leave
;
.func shl,2
;
;---------------------
;
; function Shl(Int,Cnt : Integer) : Integer;
;
; does unsigned integer shift left Cnt times
;
;---------------------
;
return .equ 00
count .equ 02
int .equ 08
;
; save parameters, etc.
;
pop return ; save return address, etc.
clrstk
popb count
ldy count
beq quick_exit
pop int
;
; shift left until done (feed 0's into msb)
;
loop asl int
rol int+1
dey
bne loop
;
; return integer and exit
;
push int
quick_exit
push return
rts
;
.func iand,2
;
;----------------------
;
; function IAnd(Int1,Int2 : Integer) : Integer;
;
; returns (Int1 AND Int2)
;
;----------------------
;
return .equ 00
int2 .equ 06
int1 .equ 08
;
;
pop return ; save return address
clrstk ; clear stack
pop int2 ; save parms
pop int1
lda int2+1 ; get upper byte of Int2
and int1+1 ; AND with upper byte of Int1
pha ; and save on stack
lda int2 ; ditto with lower bytes
and int1
pha
push return
rts
;
.func ior,2
;
;----------------------
;
; function IOr(Int1,Int2 : Integer) : Integer;
;
; returns (Int1 OR Int2)
;
;----------------------
;
return .equ 00
int2 .equ 06
int1 .equ 08
;
;
pop return ; save return address
clrstk ; clear stack
pop int2 ; save parms
pop int1
lda int2+1 ; get upper byte of Int2
ora int1+1 ; OR with upper byte of Int1
pha ; and save on stack
lda int2 ; ditto with lower bytes
ora int1
pha
push return
rts
;
.func ixor,2
;
;----------------------
;
; function IXor(Int1,Int2 : Integer) : Integer;
;
; returns (Int1 XOR Int2)
;
;----------------------
;
return .equ 00
int2 .equ 06
int1 .equ 08
;
;
pop return ; save return address
clrstk ; clear stack
pop int2 ; save parms
pop int1
lda int2+1 ; get upper byte of Int2
eor int1+1 ; XOR with upper byte of Int1
pha ; and save on stack
lda int2 ; ditto with lower bytes
eor int1
pha
push return
rts
;
.func low
;
;---------------------
;
; function Low(Int : Integer) : Integer
;
; return low-order byte of Int
;
;--------------------
;
return .equ 00
int .equ 02
;
;
pop return ; save return address
clrstk ; and clear stack
popb int ; save lower byte of Int
pushb int ; push it back on
push return ; restore return address
rts
;
.func high
;
;---------------------
;
; function High(Int : Integer) : Integer
;
; return high-order byte of Int
;
;--------------------
;
return .equ 00
int .equ 02
;
;
pop return ; save return address
clrstk ; and clear stack
pop int ; save Int
pushb int+1 ; push high-order byte back on
push return ; restore return address
rts
;
.func swap
;
;---------------------
;
; function Swap(Int : Integer) : Integer
;
; swaps high and low byte of Int
;
;--------------------
;
return .equ 00
;
;
pop return ; save return address
clrstk ; and clear stack
pla ; get lower byte
tax ; and save in X-register
pla ; get upper byte
tay ; and save in Y-register
txa ; push back on stack in swapped order
pha
tya
pha
push return ; restore return address
rts
;
.proc create,2
;
;---------------------
;
; procedure Create(Addr : Integer; var Pointer)
;
; sets Pointer to Addr
;
;--------------------
;
return .equ 00
pointer .equ 02
;
;
pop return ; save return address
pop pointer ; get addr of pointer
ldy #00 ; set up for indexing
pla ; move address into pointer
sta (pointer),y
pla
iny ; increment to next location
sta (pointer),y
push return ; restore return address
rts
;
.func address,1
;
;---------------------
;
; function Address(var Item)
;
; return address of any variable
;
;--------------------
;
return .equ 00
;
;
pop return ; save return address
clrkstk ; clear stack but leave address of Item
; on it as function result
push return ; restore return address
rts
;
.end